﻿using Client.Constant;
using Client.Framework.Message;
using Client.Model;
using Client.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Client.Message.Response
{
    [MessageAttr(MessageId.ORG_LIST)]
    class OrgListResp : ResponseBaseMessage
    {
        public List<ViewOrg> Orgs { get; } = new List<ViewOrg>();
        public int Count { get; set; }

        public override void Deserialize(byte[] buffer)
        {
            OrgList msg = OrgList.Parser.ParseFrom(buffer);
            foreach (var org in msg.Orgs)
            {
                ViewOrg viewOrg = new ViewOrg
                {
                    ID = org.Id,
                    ParentId = org.ParentId,
                    ParentOrgName = OrgService.Instance().GetOrgById(org.ParentId) == null ? "根组织" : OrgService.Instance().GetOrgById(org.ParentId).OrgName,
                    OrgName = org.OrgName,
                    Status = (Enum.DataStatus)org.Status,
                    Sort = org.Sort,
                    Creator = org.Creator,
                    CreateTime = org.CreateTime,
                    Updator = org.Updator,
                    UpdateTime = org.UpdateTime
                };
                Orgs.Add(viewOrg);
            }
            Count = msg.Count;
        }
    }
}
